function [handle] = textentry(tag, label, initvalue, fieldwidth, x, y, varargin)
% textentry.m - make a textbox with a label
% call: textbox(tag, label, initvalue, x, y)
% x and y are in character units...

% modified 4/5/2008 P. Manis to allow label to be a button that executes
% another way to fill the field

b_ht = 1.8; % standard field height in characters
pad_static=4;
pad_edit=5;
fontsz=10;
backcolor=[0.0 0.0 0.0];

fwtitle = length(label)+pad_static;
fwarg = fieldwidth+pad_edit - fwtitle;
if(fwarg < (length(initvalue)+pad_edit+1))
    fwarg = length(initvalue)+pad_edit+1;
end
if(nargin > 6) % special call for textentry - use label as a button, and 7th arg is the callback
    fcallback = varargin{1}; % count starts at end of defined variables
    uicontrol('Units','characters', ...
        'ListboxTop',0, ...
        'foregroundcolor', 'white', ...
        'backgroundcolor', 'blue', ...
        'Position',[x y fwtitle b_ht], ...
        'HorizontalAlignment','left', ...
        'String',label, ...
        'Style','pushbutton', ...
        'callback', fcallback, ...
        'FontSize', fontsz+1);
else

    uicontrol('Units','characters', ...
        'ListboxTop',0, ...
        'foregroundcolor', 'white', ...
        'backgroundcolor', backcolor, ...
        'Position',[x y fwtitle b_ht], ...
        'HorizontalAlignment','left', ...
        'String',label, ...
        'Style','text', ...
        'FontSize', fontsz);
end;

handle = uicontrol('Units','characters', ...
    'ListboxTop',0, ...
    'background', [1 1 1], ...
    'foreground', 'black', ...
    'Position',[x+fwtitle y fwarg b_ht], ...
    'HorizontalAlignment','right', ...
    'Max', 1, ...
    'Min', 0, ...
    'Style','edit', ...
    'FontSize', fontsz, ...
    'Tag',tag);
set(handle, 'String', initvalue);
return

